import { Component, Injector } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { nailerService } from '../../../../providers/nailerService';
import { AlertController } from 'ionic-angular';
import { PIC_URL } from "../../../../providers/Config";
import { StorageService } from './../../../../providers/StorageService';
import { BasePage } from '../../../basePage';

/**
 * Generated class for the TeacherSearchPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-teacher-search',
  templateUrl: 'teacher-search.html',
})
export class TeacherSearchPage extends BasePage{
  userinfo={}
  flag=true;
  /*存放美甲师信息 */
  teacherInfo={};
  id="";
  // 参数
  param = {
    artist_id:"",
    user_id:1001,
    type:0

  }
  picture="";
  
  constructor(
    injector: Injector,
    private nailerservice:nailerService,
    public stc:StorageService) {
      super(injector);
      this.picture = PIC_URL;
      this.userinfo=this.stc.read('userinfo');
      console.log(this.userinfo)
  }

  ionViewDidLoad() {
    console.log('e');
    if(!this.id){
      this.flag=true;
    }else{
      this.flag=false;
    }
  }


  /*点击邀请入驻 */
  async a(){
    this.param.type=1;
    let param2={artist_id:this.teacherInfo['artist_id'],user_id:this.userinfo['user_id'],type:1}
    console.log(param2)
    let res =await this.nailerservice.shopInvitationNailAPI(param2);
    let toast = this.toastCtrl.create({
      message: res.msg,
      duration: 2000,
      position: 'bottom',
    })
    toast.present();
    this.flag=true;
    this.id="";
  }


  /**搜索美甲师 */
 async searchTeacher(e){
   this.param.type=0;
    if(!this.id){
      this.flag=true;
      let alert = this.alertCtrl.create({
        //title: '错误！',
        subTitle: 'ID不能为空',
        buttons: ['确定']
      });
      alert.present();
    
    }else{
      this.flag=true;
      //console.log(this.id);
      this.param.artist_id=this.id;
      // console.log(this.id);
      let res = await this.nailerservice.shopInvitationNailAPI(this.param);
       console.log(res);
        if(res){
          if(this.id==res.artist_id){
            this.flag=false;
            this.teacherInfo = res;
            console.log(this.teacherInfo);
          }else{
            this.flag=true;
            //console.log("请输入正确的ID！");
            let alert = this.alertCtrl.create({
              //title: '错误！',
              subTitle: 'ID不存在，请输入正确ID！',
              buttons: ['确定']
            });
            alert.present();
          }
         }
   
      }
  }

}